<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>角色详情 - 权限管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #4361ee, #3f37c9);
        }

        .info-card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.08);
        }

        .role-header {
            background: linear-gradient(135deg, #4361ee, #3f37c9);
            color: white;
            border-radius: 15px 15px 0 0;
            padding: 2rem;
        }

        .permission-item {
            border-left: 4px solid #4361ee;
            padding: 15px;
            margin-bottom: 10px;
            background: #f8f9fa;
            border-radius: 0 8px 8px 0;
            transition: all 0.3s ease;
        }

        .permission-item:hover {
            background: #e9ecef;
            transform: translateX(5px);
        }

        .menu-icon {
            width: 40px;
            height: 40px;
            background: linear-gradient(45deg, #4895ef, #4361ee);
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            margin-right: 15px;
        }
    </style>
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-dark gradient-bg shadow">
    <div class="container">
        <a class="navbar-brand" href="${pageContext.request.contextPath}/">
            <i class="bi bi-shield-lock-fill me-2"></i>权限管理系统
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link" href="${pageContext.request.contextPath}/">
                        <i class="bi bi-house-door me-1"></i>首页
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="${pageContext.request.contextPath}/users">
                        <i class="bi bi-people me-1"></i>用户管理
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="${pageContext.request.contextPath}/roles">
                        <i class="bi bi-person-badge me-1"></i>角色管理
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<!-- 主内容 -->
<div class="container my-5">
    <c:choose>
        <c:when test="${not empty role}">
            <!-- 角色基本信息 -->
            <div class="card info-card mb-4">
                <div class="role-header">
                    <div class="row align-items-center">
                        <div class="col-md-8">
                            <h2 class="mb-2">
                                <i class="bi bi-shield-check me-3"></i>${role.name}
                            </h2>
                            <p class="lead mb-0">${role.description}</p>
                        </div>
                        <div class="col-md-4 text-end">
                            <span class="badge bg-light text-dark fs-6">角色ID: ${role.id}</span>
                            <div class="mt-2">
                                <c:choose>
                                    <c:when test="${role.status == 0}">
                                        <span class="badge bg-success fs-6">启用</span>
                                    </c:when>
                                    <c:when test="${role.status == 1}">
                                        <span class="badge bg-danger fs-6">禁用</span>
                                    </c:when>
                                </c:choose>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <div class="row text-center">
                        <div class="col-md-4">
                            <div class="border-end py-3">
                                <h5 class="text-primary">
                                    <i class="bi bi-calendar me-2"></i>创建时间
                                </h5>
                                <p class="mb-0">${role.createTime}</p>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="border-end py-3">
                                <h5 class="text-primary">
                                    <i class="bi bi-arrow-clockwise me-2"></i>更新时间
                                </h5>
                                <p class="mb-0">${role.updateTime}</p>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="py-3">
                                <h5 class="text-primary">
                                    <i class="bi bi-collection me-2"></i>权限数量
                                </h5>
                                <p class="mb-0">${not empty role.menus ? role.menus.size() : 0}</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 角色权限信息 -->
            <div class="card info-card">
                <div class="card-header bg-white">
                    <h4 class="card-title mb-0 text-primary">
                        <i class="bi bi-list-check me-2"></i>权限信息
                    </h4>
                </div>
                <div class="card-body">
                    <c:choose>
                        <c:when test="${not empty role.menus}">
                            <div class="row">
                                <c:forEach var="menu" items="${role.menus}">
                                    <div class="col-lg-6 mb-3">
                                        <div class="permission-item">
                                            <div class="d-flex align-items-center">
                                                <div class="menu-icon">
                                                    <i class="bi
                                                            <c:choose>
                                                                <c:when test="${menu.type == 0}">bi-folder</c:when>
                                                                <c:when test="${menu.type == 1}">bi-gear</c:when>
                                                                <c:otherwise>bi-file-earmark</c:otherwise>
                                                            </c:choose>
                                                        "></i>
                                                </div>
                                                <div class="flex-grow-1">
                                                    <h6 class="mb-1">${menu.name}</h6>
                                                    <p class="text-muted mb-1 small">
                                                        <i class="bi bi-link-45deg me-1"></i>
                                                            ${not empty menu.url ? menu.url : '无链接'}
                                                    </p>
                                                    <div class="d-flex justify-content-between align-items-center">
                                                        <small class="text-muted">
                                                            排序: ${menu.orderNo}
                                                        </small>
                                                        <span class="badge
                                                                <c:choose>
                                                                    <c:when test="${menu.type == 0}">bg-primary</c:when>
                                                                    <c:when test="${menu.type == 1}">bg-success</c:when>
                                                                    <c:otherwise>bg-secondary</c:otherwise>
                                                                </c:choose>
                                                            ">
                                                                <c:choose>
                                                                    <c:when test="${menu.type == 0}">菜单</c:when>
                                                                    <c:when test="${menu.type == 1}">按钮</c:when>
                                                                    <c:otherwise>其他</c:otherwise>
                                                                </c:choose>
                                                            </span>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </c:forEach>
                            </div>
                        </c:when>
                        <c:otherwise>
                            <div class="text-center py-5">
                                <i class="bi bi-inbox display-1 text-muted mb-3"></i>
                                <h5 class="text-muted">该角色暂无权限</h5>
                                <p class="text-muted">请为角色分配相应的菜单权限</p>
                            </div>
                        </c:otherwise>
                    </c:choose>
                </div>
            </div>
        </c:when>
        <c:otherwise>
            <!-- 角色不存在 -->
            <div class="card info-card">
                <div class="card-body text-center py-5">
                    <i class="bi bi-exclamation-triangle display-1 text-warning mb-3"></i>
                    <h3 class="text-warning">角色不存在</h3>
                    <p class="text-muted mb-4">未找到指定的角色信息，请检查角色ID或名称是否正确</p>
                    <a href="${pageContext.request.contextPath}/roles" class="btn btn-primary">
                        <i class="bi bi-arrow-left me-2"></i>返回角色列表
                    </a>
                </div>
            </div>
        </c:otherwise>
    </c:choose>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>